feat(swarm): add list_checkpoints tool and checkpoint name discovery - #476
feat(swarm): add list_checkpoints tool and checkpoint name discovery#476openjiuwen-sync-bot[bot] wants to merge 3 commits into
Conversation
|
|
|
head_sha: 变更摘要此 PR 主要解决了命名 checkpoint 的三个可发现性问题:名字无固定渠道传递给 leader、leader 无法查询已有 checkpoint、以及 fork 用错名字时静默回退。通过将 checkpoint 记录格式从简单整型升级为结构化字典 主要改动
|
|
head_sha: 代码审查✅ 未发现问题 |
Paired: GitHub #476 ↔ GitCode !2291
加入 list_checkpoint 工具
What type of PR is this?
/kind feature
背景
F_76 持久化后,命名 checkpoint 仍存在三个可发现性问题:
checkpoint()的结果只写进调用成员自己的上下文,leader 是否知道名字完全取决于成员自觉send_message+ leader 猜对字符串。_named_checkpoints(F_76 后持久化于 session namespace),但没有任何团队工具把它暴露给 LLM。fork="<wrong>"找不到时只记日志 warning,然后静默回退为全量继承,leader 完全不知情。方案
1. checkpoint 记录格式扩展(可查的前提)
快照从
name → message_count升级为name → {count, description, created_by}:runtime/metadata.py:read_team_checkpoints兼容新记录与旧intblob(兜底转空记录),脏值不炸冷恢复。agent/team_agent.py:set_checkpoint(name, count, *, description, created_by)存成记录;fork 解析改为取record["count"](截断行为不变)。tools/team.py:store_checkpoint组装记录、默认created_by=member_name。spawn/inprocess_spawn.py:store 回调直传 leaderset_checkpoint,description/created_by 自动透传。2.
list_checkpoints工具(leader-only 查询)tools/tool_member.py:新增ListCheckpointsTool,零参数,返回[{name, message_count, description, created_by}];map_result逐行渲染,空集返回"No checkpoints"。tools/team.py:set_checkpoint_list_fn/list_checkpoints()(优先回调取 leader 的_named_checkpoints,否则兜底本地 dict)。agent/team_agent.py_setup_infra:leader 接线set_checkpoint_list_fn(lambda: self._named_checkpoints)。tools/tool_factory.py注册;tools/tool_permissions.py加入LEADER_ONLY_TOOLS(外部 member scope 按角色过滤、operator 控制面不经create_team_tools,天然不可见)。tools/locales/descs/en|cn/list_checkpoints.md:描述含"fork 前必须调用核对名字"契约。3. 成员打 checkpoint 自动通知 leader
tools/tool_member.pyCheckpointTool:保存后调_notify_leader_created——非 leader 成员自动send_message给 leader,内容[checkpoint] 'name' created by member at message N (description)。tools/locales/en.py/cn.py:新增checkpoint.notify_leader文案。4. fork 名不匹配可见化
agent/team_agent.py:新增_notify_fork_name_not_found,命名 fork 找不到时 best-effort 给 leader 发消息,列出可用 checkpoint 清单;不阻断 spawn(仍回退全量)。i18n.py:新增checkpoint.fork_not_found(cn/en)。5. 描述契约
tools/locales/descs/en|cn/checkpoint.md:增补"告知 Leader"段(打快照后必须报名字;leader 可用list_checkpoints核对)。tools/locales/descs/en|cn/spawn_teammate.md:fork 机制段补"fork 前先list_checkpoints拿权威名字"。修改文件
新增文件
tools/locales/descs/en/list_checkpoints.mdtools/locales/descs/cn/list_checkpoints.md修改文件
runtime/metadata.pyread/merge_team_checkpoints记录格式 + 旧 int 兜底tools/team.pyset_checkpoint_list_fn/list_checkpoints;store_checkpoint默认created_by=member_nameagent/team_agent.pyset_checkpoint记录;fork 解析取record["count"];_setup_infra接线 list fn;_notify_fork_name_not_foundspawn/inprocess_spawn.pyset_checkpointtools/tool_member.pyCheckpointTool带 description/created_by + 自动通知 leader;新增ListCheckpointsTooltools/tool_factory.pylist_checkpointstools/tool_permissions.pyLEADER_ONLY_TOOLS加list_checkpointstools/locales/en.py、cn.pycheckpoint.notify_leaderi18n.pycheckpoint.fork_not_found(cn/en)docs/specs/S_04_session-and-recovery.mdcheckpoints字段同步为记录格式{count, description, created_by}docs/specs/S_12_schema-data-models.mdcheckpoints字段同步为记录格式tests/unit_tests/agent_teams/test_fork.pylist_checkpoints×2、记录断言)tests/unit_tests/agent_teams/test_team_tools.pyTestListCheckpointsTool(+5)tests/unit_tests/agent_teams/runtime/test_metadata.pytests/unit_tests/agent_teams/test_runner_team_runtime.py使用示例
验证
test_fork.pylist_checkpoints/ 记录断言)test_team_tools.pyTestListCheckpointsTool+5)test_tool_variants.pylist_checkpoints装配冒烟,en/cn desc 覆盖)test_metadata.pytest_runner_team_runtime.pySelf-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)